var express = require('express');
var server = express();
var serverPost = require("./compose/serverPost.js")
server.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method' )
  res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE')
  res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE')
    next();
});
server.use(express.static(__dirname + '/public'));
// console.log("Web server has started.\nPlease log on http://127.0.0.1:3001/index.html");
server.use(express.json());
server.use(express.urlencoded({extended:true}));

var collection = require("./compose/collection.js")
server.collection = collection
collection.init(server)
serverPost.init(server)
server.listen(80);
process.on('uncaughtException', function (err) {
  console.error(' Caught exception: ' + err.stack);
});